package com.zzx.test.temp;

import javax.swing.*;
import java.awt.*;

public class RotatingStar extends JComponent {
    private static final long serialVersionUID = 1L;
    private int angle = 0;

    public void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D)g;
        g2.rotate(Math.toRadians(angle), getWidth()/2, getHeight()/2);

        int xpoints[] = {55, 67, 109, 73, 83, 55, 27, 37, 1, 43};
        int ypoints[] = {0, 36, 36, 54, 96, 72, 96, 54, 36, 36};
        int npoints = 10;

        Polygon star = new Polygon(xpoints, ypoints, npoints);
        g2.fill(star);
    }

    public void animate() {
        while (true) {
            angle++;
            if (angle == 360) {
                angle = 0;
            }
            repaint();
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setSize(200, 200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("Rotating Star");

        RotatingStar star = new RotatingStar();
        frame.add(star);
        frame.setVisible(true);
        star.animate();
    }
}